<template>
  <div>
    <div v-if="show1" class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="店铺名称" prop="merName">
          <el-input v-model="queryParams.merName" placeholder="请输入店铺名称" clearable
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item label="详细地址" prop="merAddress">
          <el-input v-model="queryParams.merAddress" placeholder="请输入详细地址" clearable
                    @keyup.enter.native="handleQuery"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                     v-hasPermi="['carService:merchant:add']">新增
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                     v-hasPermi="['carService:merchant:edit']">修改
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                     v-hasPermi="['carService:merchant:remove']">删除
          </el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                     v-hasPermi="['carService:merchant:export']">导出
          </el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="merchantList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="ID" align="center" prop="id"/>
        <el-table-column label="店铺名称" align="center" prop="merName"/>
        <el-table-column label="注册时间" align="center" prop="registrationTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.registrationTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="详细地址" align="center" prop="merAddress"/>
        <el-table-column label="审核状态" align="center" prop="auditStatus">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.car_mer_status" :value="scope.row.auditStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row)">详情</el-button>
            <el-button v-if="scope.row.auditStatus == 0" size="mini" type="text" icon="el-icon-edit"
                       @click="handleUpdate(scope.row)"
                       v-hasPermi="['carService:merchant:edit']">审核
            </el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                       v-hasPermi="['carService:merchant:remove']">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                  @pagination="getList"/>

      <!-- 添加或修改商户管理对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <!-- <el-form-item label="审核状态" prop="auditStatus">
              <el-radio-group v-model="form.auditStatus">
                <el-radio v-for="dict in dict.type.car_mer_status" :key="dict.value"
                  :label="dict.value">{{ dict.label }}</el-radio>
              </el-radio-group>
          </el-form-item> -->
          <el-form-item label="审核状态" prop="auditStatus">
            <el-radio-group v-model="form.auditStatus">
              <el-radio
                v-for="dict in filteredDict"
                :key="dict.value"
                :label="parseInt(dict.value, 10)"
              > {{ dict.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审核意见" prop="auditOpinion">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入审核意见"
                      :autosize="{minRows: 4, maxRows: 4}" :style="{width: '90%'}"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>

    </div>
    <div v-if="!show1">
      <div style="position: absolute;left: 1250px;top: 10px;">
        <el-button type="primary"  @click="show1 = !show1">返回</el-button>
      </div>
      <h3>店铺信息</h3>
      <hr>
      <div class="ti"><strong style="font-size: 26px;">店铺信息</strong></div>
      <div class="shop-info">
        <table ref="form" :model="form">
          <tr>
            <th>商户名称</th>
            <td>{{ form.merName }}</td>
            <th>营业执照号码</th>
            <td>{{ form.carMerchantVerification.merLicenseNumber }}</td>
          </tr>
          <tr>
            <th>负责人姓名</th>
            <td>{{ form.carMerchantPrincipal.pcpName }}</td>
            <th>负责人手机号码</th>
            <td>{{ form.carMerchantPrincipal.phoneNumber }}</td>
          </tr>
          <tr>
            <th>身份证号码</th>
            <td>{{ form.carMerchantPrincipal.idNumber }}</td>
            <th>经营区域</th>
            <td>{{ form.merArea }}</td>
          </tr>
          <tr>
            <th>注册时间</th>
            <td>{{ form.registrationTime }}</td>
            <th>审核状态</th>
            <td>{{ formattedAuditStatus }}</td>
          </tr>
          <tr>
            <th>详细地址</th>
            <td colspan="3">{{ form.merAddress }}</td>
          </tr>
          <tr>
            <th>简介</th>
            <td colspan="3">{{ form.merIntroduction }}</td>
          </tr>
        </table>

      </div>
      <div class="ti"><strong style="font-size: 26px;">店铺信息</strong></div>
      <div class="sound-scenes">
<!--        <div class="scene" v-for="(scene, index) in scenes" :key="index">
          <img :src="scene.image" alt="Scene" class="scene-image">
          <p class="scene-label">{{ scene.label }}</p>
        </div>-->
        <div class="scene">
          <img :src="this.form.imgPath" alt="Scene" class="scene-image">
          <p class="scene-label">门面照片</p>
        </div>
        <div class="scene">
          <img :src="this.form.carMerchantVerification.merLicenseImage" alt="Scene" class="scene-image">
          <p class="scene-label">营业执照</p>
        </div>
        <div class="scene">
          <img :src="this.form.carMerchantPrincipal.idCardFront" alt="Scene" class="scene-image">
          <p class="scene-label">身份证国徽照</p>
        </div>
        <div class="scene">
          <img :src="this.form.carMerchantPrincipal.idCardBack" alt="Scene" class="scene-image">
          <p class="scene-label">身份证人像照</p>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import {listMerchant, getMerchant, delMerchant, addMerchant, updateMerchant} from "@/api/carService/merchant";

export default {
  name: "Merchant",
  dicts: ['car_mer_status'],
  data() {
    return {
      show1: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商户管理表格数据
      merchantList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        merName: null,
        merAddress: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        merName: [
          {required: true, message: "店铺名称不能为空", trigger: "blur"}
        ],
        merArea: [
          {required: true, message: "经营区域不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  computed: {
    filteredDict() {
      return this.dict.type.car_mer_status.filter(item => item.value !== '0');
    },
    formattedAuditStatus() {
      switch (this.form.auditStatus) {
        case '0':
          return '未审核';
        case '1':
          return '已通过';
        case '2':
          return '已拒绝';
        default:
          return '未知状态';
      }
    }
  },
  methods: {
    /** 查询商户管理列表 */
    getList() {
      this.reset();
      this.loading = true;
      listMerchant(this.queryParams).then(response => {
        this.merchantList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        merName: null,
        merArea: null,
        registrationTime: null,
        startMerTime: null,
        stopMerTime: null,
        merAddress: null,
        longitude: null,
        latitude: null,
        merIntroduction: null,
        merRating: null,
        merStatus: null,
        deleteStatus: null,
        auditStatus: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商户管理";
    },
    /** 详情按钮操作*/
    handleDetail(row) {
      this.show1 = false;
      this.reset();
      const id = row.id || this.ids
      getMerchant(id).then(response => {
        this.form = response.data;
      });
    },

    /** 修改 审核按钮操作 */
    handleUpdate(row) {
      console.log("row==>start")
      console.log(row)
      console.log("row==>over")
      this.reset();
      const id = row.id || this.ids

      getMerchant(id).then(response => {
        this.form = response.data;
        this.form.remark=null;
        this.open = true;
        console.log("row==>start")
        console.log(id)
        console.log("row==>over")
        this.title = "修改商户管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMerchant(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMerchant(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商户管理编号为"' + ids + '"的数据项？').then(function () {
        return delMerchant(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('carService/merchant/export', {
        ...this.queryParams
      }, `merchant_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped lang="scss">
.shop-info table {
  width: 1250px;
  border-collapse: collapse;
  margin: 0px 30px 10px 30px;
}

.ti {
  font-size: 20px;
  margin: 0px 30px 10px 30px;
}

.shop-info th,
.shop-info td {
  border: 1px solid #ccc;
  height: 45px;
  padding: 8px;
  text-align: center;
}

.shop-info th {
  background-color: #f2f2f2;
}

.sound-scenes {
  display: flex;
  //flex-direction: column; /* 或者使用 row 如果你希望它们水平排列 */
  align-items: center;
  gap: 20px;

  /* 在项目之间添加间距 */
  .scene {
    margin: 0px 30px 0px 30px;
    text-align: center;
  }

  .scene-image {
    width: 200px;
    /* 或者你想要的任何宽度 */
    height: 150px;
    /* 保持图片的原始宽高比 */
  }

  .scene-label {
    margin-top: 10px;
  }
}
</style>
